﻿namespace My.Hydrator.Helpers
{
    using System.Collections.Generic;
    using System.ComponentModel.Composition;
    using System.ComponentModel.Composition.Hosting;
    using System.Reflection;
    using My.Hydrator.Conventions;
    using My.Hydrator.Formatters;

    public class Container
    {
        public Container()
        {
            this.CustomConventions = new Dictionary<string, IDictionary<string, ITypeConvention>>();

            var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
            var container = new CompositionContainer(catalog);
            container.SatisfyImportsOnce(this);

            SessionHelper.Container = this;
        }

        [ImportMany(typeof(ITypeConvention))]
        public List<ITypeConvention> Conventions { get; set; }

        public IDictionary<string, IDictionary<string, ITypeConvention>> CustomConventions { get; set; }

        [ImportMany(typeof(IDataTypeFormatter), AllowRecomposition = true, RequiredCreationPolicy = CreationPolicy.Shared)]
        public List<IDataTypeFormatter> Formatters { get; set; }
    }
}
